/**
 * 
 */
package com.wrsr.examsys.card.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wrsr.examsys.base.dao.BaseDao;
import com.wrsr.examsys.base.service.impl.BaseServiceImpl;
import com.wrsr.examsys.card.service.DiscussService;
import com.wrsr.examsys.domain.Card;
import com.wrsr.examsys.domain.Discuss;

/**
 * @author <a href="mailto:2397431783@qq.com">wangruishun</a>
 *
 *         2015年5月8日
 */
@Service("discussService")
public class DiscussServiceImpl extends BaseServiceImpl<Discuss> implements
		DiscussService {

	@SuppressWarnings("rawtypes")
	@Override
	@Resource(name = "discussDao")
	public void setDao(BaseDao dao) {
		super.setDao(dao);
	}

	@Override
	public List<Discuss> getDiscussByPage(int offset, int length) {
		String hql = "from Discuss d where d.deleteFlag=1";
		return super.getListForPage(hql, offset, length);
	}

	@Override
	public Integer getTotal() {
		String hql = "from Discuss d where d.deleteFlag=1";
		List<Discuss> discusss = super.findEntityByHQL(hql, 1);
		if (discusss == null || discusss.isEmpty()) {
			return 0;
		} else {
			return discusss.size();
		}

	}
	public Integer studentGetMsgFromDiscuss(String fromId){
		String hql="from Discuss d where d.state=? and d.cardId IN ( select c.cardId from Card c where c.deleteFlag=? and c.fromId=?)";
		//String hql="from Discuss c where c.deleteFlag=? and state=? and c.fromId=?";
		List<Discuss> discusss=super.findEntityByHQL(hql, 0,1,fromId);
		if (discusss == null || discusss.isEmpty()) {
			return 0;
		} else {
			return discusss.size();
		}
	}

	

}
